<script setup lang="ts">
// import {  RouterView } from 'vue-router'

import { http } from '@/api/request'
import { ref } from 'vue'
import router from '@/router'
import exmValue from "@/assets/exmple.json"
const axios = new http()
const getActive = () => {
  const tk = uuidv4()
  router.push({ query: { token: tk } })
  axios
    .post('/sdapi/v1/img2img', {
      token: tk
    })
    .then((result: any) => {
      data.value = result
      console.log(result)
    })
    .catch((err: any) => {
      console.log(err)
      error.value = err
    })

  const tm = setInterval(() => {
    axios.get('/active?token=' + tk)
  }, 1000)
  setTimeout(() => {
    clearInterval(tm)
    console.log('清除定时器')
  }, 5000)
}

function uuidv4() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    var r = (Math.random() * 16) | 0,
      v = c == 'x' ? r : (r & 0x3) | 0x8
    return v.toString(16)
  })
}
const data = ref('')
const error = ref('')

const startCalc = () => {
  const tk = uuidv4()
  axios
    .post('/sdapi/v1/img2img?token=' + tk, exmValue)
    .then((result: any) => {
      data.value = result
      console.log(result)
    })
    .catch((err: any) => {
      console.log(err)
      error.value = err
    })
    let url = 'http://localhost:3001/#/active?token=' + tk;
    window.open(url, '_blank');
}
</script>

<template>
  <div ></div>
    <div class="btn-animate btn-animate__overlap-horizontal" @click="startCalc">
    <span >启动</span>
  </div>
</template>

<style scoped lang="scss">
.btn-animate {
  position: relative;
  width: 130px;
  height: 40px;
  line-height: 40px;
  margin-right: 10px;
  border: none;
  border-radius: 5px;
  background: #027efb;
  color: #fff;
  text-align: center;
  cursor: pointer;
}

.btn-animate__overlap-horizontal {
  z-index: 1;

  &::after {
    left: auto;
    right: 0;
  }

  &::before,
  &::after,
  & > span::before,
  & > span::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: rgba(144, 207, 91, 0.25);
    transition: 0.4s;
    z-index: -1;
  }

  & > span::before,
  & > span::after {
    transition-delay: 0.4s;
  }

  & > span::before {
    left: auto;
    right: 0;
  }

  &:hover {
    &::before,
    &::after,
    & > span::before,
    & > span::after {
      width: 100%;
    }
  }
}
</style>
